﻿///-----------------------------------------------------------------------
/// <copyright file="MainWindowViewModel.cs" company="FactSet Research Systems, Inc.">
///     Copyright © FactSet Research Systems, Inc.  All rights reserved 2012.
/// </copyright>
/// <author>Jonathan K. Barez</author>
///-----------------------------------------------------------------------

using System.Windows;
using System.Windows.Controls;
using MVVMCore.ViewModel.Details;

namespace HousholdISv2.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using MVVMCore.ViewModel;
    using System.Collections.ObjectModel;
    using GalaSoft.MvvmLight.Messaging;

    public class MainWindowViewModel : ViewModelBase
    {
        #region Fields

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        public MainWindowViewModel()
        {
        }

        #endregion Constructors

        #region Events

        #endregion Events

        #region Properties

        public ObservableCollection<ViewModelBase> Views
        {
            get { return GetValue(() => this.Views) ?? this.InitializeViewsCollection(); }
            set { SetValue(() => this.Views, value); }
        }

        private CommandCollectionViewModel MainMenu
        {
            get { return GetValue(() => this.MainMenu) ?? this.InitializeMainMenu(); }
            set { SetValue(() => this.MainMenu, value); }
        }

        #endregion Properties

        #region Methods

        private ObservableCollection<ViewModelBase> InitializeViewsCollection()
        {
            var views =
                new ObservableCollection<ViewModelBase>
                    {
                        this.MainMenu
                    };
            return this.Views = views;
        }

        private CommandCollectionViewModel InitializeMainMenu()
        {
            var main =
                new CommandCollectionViewModel
                    {
                        Orientation = Orientation.Vertical,
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        CommandSpacing = 10,
                    };
            main.AddRange(
                new CommandViewModel("Maintenance", param => this.DoMaintenance()) {Width = 200, Height = 100},
                new CommandViewModel("Transactions", param => this.DoTransactions()) {Width = 200, Height = 100},
                new CommandViewModel("Reports", param => this.DoReports()) {Width = 200, Height = 100});
            return this.MainMenu = main;
        }

        private void DoMaintenance()
        {
            this.MainMenu.Visibility = Visibility.Collapsed;
            var main = new MaintenanceTabsViewModel();
            main.BackButtonClicked +=
                (sender, e) =>
                    {
                        Views.Remove(main);
                        this.MainMenu.Visibility = Visibility.Visible;
                    };
            Views.Add(main);
        }

        private void DoTransactions()
        {
            this.MainMenu.Visibility = Visibility.Collapsed;
            var main = new TransactionTabsViewModel();
            main.BackButtonClicked +=
                (sender, e) =>
                {
                    Views.Remove(main);
                    this.MainMenu.Visibility = Visibility.Visible;
                };
            Views.Add(main);
        }

        private void DoReports()
        {
            Messenger.Send(
                new DialogMessage(
                    "Not yet implemented!",
                    delegate { })
                {
                    Button = MessageBoxButton.OK,
                    Caption = "Reports",
                    Icon = MessageBoxImage.Information
                });
        }

        #endregion Methods
    }
}
